<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserBubbles
 *
 * @property int $id 主键
 * @property int $uid 用户id
 * @property float $points 分值
 * @property int $created_at 创建时间
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserBubbles whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserBubbles whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserBubbles wherePoints($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserBubbles whereUid($value)
 * @mixin \Eloquent
 * @property int $treeid
 * @property-read \App\Models\UserTree $tree
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserBubbles whereTreeid($value)
 */
class UserBubbles extends Model
{
    protected $table = 'user_bubbles';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }

    public function tree()
    {
        return $this->belongsTo(UserTree::class, 'treeid', 'id');
    }
}
